package menu.lt.pers.menu.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.Adapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import menu.lt.pers.menu.Bean.ResultByClassIdBean;
import menu.lt.pers.menu.R;

import java.util.List;

public class MaterialRecyclerViewAdapter extends Adapter<MaterialRecyclerViewAdapter.MyHolder>{
    Context context;
    List<ResultByClassIdBean.ResultBean.ListBean.MaterialBean> list;

    public MaterialRecyclerViewAdapter(Context context, List<ResultByClassIdBean.ResultBean.ListBean.MaterialBean> list) {
        this.context = context;
        this.list = list;
    }

    public Context getContext() {
        return context;
    }
    public void update(List<ResultByClassIdBean.ResultBean.ListBean.MaterialBean> list){
        this.list = list;
        notifyDataSetChanged();
    }

    public List<ResultByClassIdBean.ResultBean.ListBean.MaterialBean> getList() {
        return list;
    }

    @NonNull
    @Override
    public MyHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater
                .from(viewGroup.getContext())
                .inflate(R.layout.activity_recipe_info_listview_material_resource,viewGroup,false);
        MyHolder holder = new MyHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull MyHolder myHolder, int i) {
        myHolder.tv_material_name.setText(list.get(i).getMname());
        myHolder.tv_material_num.setText(list.get(i).getAmount());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class MyHolder extends RecyclerView.ViewHolder {
        TextView tv_material_name;
        TextView tv_material_num;
        public MyHolder(@NonNull View itemView) {
            super(itemView);
            tv_material_name = itemView.findViewById(R.id.tv_material_name);
            tv_material_num = itemView.findViewById(R.id.tv_material_num);
        }
    }
}
